<template>
  <div class="main">
    <div class="container">
      <div class="container-top">
        <div class="top">
          <div class="title">退出登录</div>
        </div>
        <div class="userinfo">
          <p class="account">
            账号：<el-input
              v-model="userData.user_name"
              class="accountInput"
              disabled
            ></el-input>
          </p>
          <p class="modify-pass" @click="onModifyPass">【修改密码】</p>
        </div>
      </div>
      <div class="content">
        <div class="item">
          <div class="item-img">
            <img :src="avatar" alt="" v-if="avatar != ''" />
            <p v-else>{{ (userData.user_name || "").slice(0, 1) }}</p>
          </div>
          <div class="item-text">
            <p class="name">{{ userData.user_name }}</p>
            <p>{{ identity }}</p>
          </div>
          <div class="item-tel">
            {{ userData.phone }}
          </div>
        </div>
        <div class="button">
          <el-button
            type="primary"
            @click="LogOutFunction()"
            icon="el-icon-switch-button"
            class="register"
            >退出当前账号</el-button
          >
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import { Register, UserInfo } from "@/api/login";
export default {
  name: "Register",
  data() {
    return {
      Showbg: false,
      accountValue: "",
      dialogImageUrl: "",
      dialogVisible: false,
      fileList: [],
      token: "",
      avatar: "",
      imgUrl: "",
      identity: "",
      userData: "",
    };
  },
  methods: {
    LogOutFunction() {
      this.queryRegister();
      this.$router.push({
        path: "/",
      });
    },
    // 退出登录
    queryRegister() {
      Register({
        token: this.token,
      });
    },
    // 获取用户信息
    queryUserInfo() {
      UserInfo({
        token: this.token,
      }).then((result) => {
        const { data } = result;
        this.userData = data;
        if (data.avatar != "") {
          if (data.avatar.indexOf("http") === -1) {
            this.avatar = this.imgUrl + data.avatar;
          }
        } else {
          this.avatar = data.avatar;
        }
        // console.log(this.userData.user_name);
        if (data.user_type === "1") {
          this.identity = "学校管理员";
        } else if (data.user_type === "2") {
          this.identity = "项目申报用户";
        } else {
          this.identity = "专家用户中心";
        }
      });
    },
    onModifyPass() {
      this.$router.push({
        path: "/modify-pass",
      });
    },
    backgroundShow() {
      this.$emit("backgroundShow", this.Showbg);
    },
  },
  created() {
    this.imgUrl = this.GLOBAL.imgUrl;
    this.backgroundShow();
  },
  mounted() {
    const token = sessionStorage.getItem("token");
    this.token = token;
    this.queryUserInfo();
  },
};
</script>
<style lang='scss' scoped>
.main {
  font-family: "Avenir", Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  padding: 0;
  color: #242748;
  margin: 0 auto;
  position: relative;
  font-size: 18px;
  margin: 0 50px 20px 30px;
  text-align: left;
  font-family: "PingFang";
  .container {
    width: 100%;
    height: 925px;
    padding-bottom: 30px;
    background-color: #fff;
    border-radius: 10px;
    .container-top {
      .top {
        display: flex;
        margin-bottom: 30px;
        .title {
          font-size: 26px;
          font-family: "黑体";
          color: #5673ff;
          margin-right: 60px;
        }
      }
      .userinfo {
        display: flex;
        align-items: center;
        .account {
          display: flex;
          align-items: center;
          font-weight: 700;
          .accountInput {
            width: 70%;
            height: 32px;
            line-height: 32px;
          }
          /deep/.el-input__inner {
            height: 100%;
            line-height: 0;
            color: #5673ff;
            font-size: 15px;
            letter-spacing: 1px;
            background-color: #f8f9fe;
            border: solid 1px #f1f2f4;
          }
        }
        .modify-pass {
          color: #5673ff;
          font-size: 16px;
          cursor: pointer;
        }
      }
    }
    .container-top {
      padding: 33px 45px 25px;
      border-bottom: solid 1px #e7e9eb;
    }
    .content {
      padding: 40px;
      height: calc(100% - 20%);
      background: url(../../assets/images/contentBg.png) no-repeat;
      background-size: 100% 100%;
      .item {
        display: flex;
        align-items: center;
        width: 38%;
        color: #fff;
        padding: 40px 40px 30px 50px;
        margin-bottom: 210px;
        background-color: #6887fc;
        border-radius: 10px;
        .item-img {
          width: 40px;
          height: 40px;
          line-height: 40px;
          font-size: 22px;
          font-weight: 700;
          color: #6887fc;
          text-align: center;
          border-radius: 10px;
          background-color: #fff;
          box-shadow: 0px 4px 15.52px 0.48px rgba(73, 100, 245, 0.39);
          img {
            width: 100%;
            height: 100%;
          }
        }
        .item-text {
          width: 50%;
          margin-left: 30px;
          font-size: 14px;
          .name {
            font-size: 24px;
            margin-bottom: 15px;
          }
        }
        .item-tel {
          float: right;
          font-size: 24px;
        }
      }
      .register {
        padding: 8px 15px 8px 20px;
        font-size: 14px;
        font-family: "PingFang";
        letter-spacing: 1px;
        margin-right: 10px;
        background-color: #5673ff;
        border: solid 1px #2d4eff;
        box-shadow: 0px 4px 15.52px 0.48px rgba(73, 100, 245, 0.39);
        /deep/i {
          margin-right: 8px;
          font-size: 18px;
          vertical-align: middle;
        }
      }
    }
  }
}
</style>